package helper.request.contacts;

import java.sql.*;

import server.dbconnector.DatabaseConnector;
import base.User;

public class AddContactRequest implements ContactRequest {
	private static final long serialVersionUID = -425663707032852227L;
    private int currentuserid;
    private int targetuserid;
    private String name;
    public AddContactRequest(int current,int target,String name){
    	this.currentuserid=current;
    	this.targetuserid=target;
    	this.name=name;
    }
	@Override
	public User gettargetuser() {
		return null;
	}

	@Override
	public int gettargetuserid() {
		return targetuserid;
	}

	@Override
	public User getcurrentuser() {
		return null;
	}

	@Override
	public int getcurrentuserid() {
		return currentuserid;
	}

	@Override
	public boolean execute() {
		// TODO Auto-generated method stub
		return false;
	}
	public String toString(){
		return "您添加了"+name+"为好友";
	}

	@Override
	public void process(DatabaseConnector dc) throws SQLException {
		dc.commit("insert into contact(userIDFrom,userIDTo,Approved)"
				+ " values(" + currentuserid + "," + targetuserid
				+ "," + "0)");
		ResultSet rs=dc.query("select * from user where ID="+this.currentuserid);
		rs.first();
		String thisname=rs.getString(4);
		dc.commit("insert into message(msgToUserID,msgFromUserID,message,ReplyNeeded)"+" values("+targetuserid+","+currentuserid+","+"'Contact request from "+thisname+"',1)");
	}

}
